package com.human.server.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.human.server.entity.Departments;
import com.human.server.entity.KpiFillDetails;
import com.human.server.model.R;
import com.human.server.model.request.KpiFillDetailRequest;
import com.human.server.service.impl.KpiFillDetailsServiceImpl;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * KPI填写详情表 前端控制器
 * </p>
 *
 * @author zooy
 * @since 2025-09-11
 */
@RestController
@RequestMapping("/human/kpiFillDetails")
public class KpiFillDetailsController {

    @Autowired
    private KpiFillDetailsServiceImpl kpiFillDetailsService;

    /**
     * 新增
     *
     * @param kpiFillDetailsList KPI填写详情表
     * @return 新增结果
     */
    @PostMapping("/submitKpi")
    public R add(@RequestBody List<KpiFillDetails> kpiFillDetailsList) {
        kpiFillDetailsService.add(kpiFillDetailsList);
        return R.success();
    }

    /**
     * 删除
     *
     * @param id 主键
     * @return 删除结果
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Long id) {
        return R.success(kpiFillDetailsService.removeById(id));
    }

    /**
     * 修改
     *
     * @param kpiFillDetails KPI填写详情表
     * @return 修改结果
     */
    @PostMapping("/update")
    public R update(@RequestBody KpiFillDetails kpiFillDetails) {
        return R.success(kpiFillDetailsService.updateById(kpiFillDetails));
    }

    /**
     * 查询
     *
     * @param id 主键
     * @return 查询结果
     */
    @PostMapping("/query")
    public R query(@RequestBody Long id) {
        return R.success(kpiFillDetailsService.getById(id));
    }

    /**
     * 列表
     *
     * @return 列表结果
     */
    @PostMapping("/list")
    public R list(@RequestBody KpiFillDetailRequest kpiFillDetailRequest) {
        return R.success(kpiFillDetailsService.list(new LambdaQueryWrapper<KpiFillDetails>()
                .eq(KpiFillDetails::getFillId, kpiFillDetailRequest.getFillId())
        ));
    }

    /**
     * 分页查询
     *
     * @param kpiFillDetailRequest 分页参数
     * @return 分页结果
     */
    @PostMapping("/page")
    public R page(@RequestBody KpiFillDetailRequest kpiFillDetailRequest) {
        return R.success(kpiFillDetailsService.page(kpiFillDetailRequest));
    }

    /**
     * updateManagerScore
     * @return
     */
    @PostMapping("updateManagerScore")
    public R updateManagerScore(@RequestBody KpiFillDetails kpiFillDetails) {
        kpiFillDetailsService.updateManagerScore(kpiFillDetails);
        return R.success(kpiFillDetails);
    }

    /**
     * updateFinalScore
     * @param kpiFillDetails
     * @return
     */
    @PostMapping("updateFinalScore")
    public R updateFinalScore(@RequestBody KpiFillDetails kpiFillDetails) {
        kpiFillDetailsService.updateFinalScore(kpiFillDetails);
        return R.success(kpiFillDetails);
    }

    /**
     * AI 分析
     * @param kpiFillDetails
     * @return
     */
    @PostMapping("aiAnalysis")
    public R aiAnalysis(@RequestBody KpiFillDetails kpiFillDetails) {

        return R.success(kpiFillDetailsService.analysis(kpiFillDetails));
    }

    /**
     * getKpiScore
     * @return
     */
    @PostMapping("getKpiScore")
    public R getKpiScore() {
        return R.success(kpiFillDetailsService.getKpiScore());
    }
}
